#!/usr/bin/python

"""
Author:			Jimmy Saw
Date modified:	06-24-2012

Description:    This script can draw pie chart of COG categories.

Usage:          dissertation_CogPieChart.py <cog count file>

Example:        dissertation_CogPieChart.py test.txt
                run here /host/Users/JS/UH-work/cave_biofilm/analysis-work/COGs
Note:           

"""

from pylab import *

def calFrac(count, total):
    f = (count / total) * 100
    return f

cogfile = open(sys.argv[1], "rU")
cf = cogfile.readlines()

total = 0

labels = []
fracs = []

for i in cf:
    st = i.split('\t')
    labels.append(st[0])
    total += float(st[1].strip())
    count = float(st[1].strip())

for i in cf:
    st = i.split('\t')
    count = float(st[1].strip())
    fracs.append(calFrac(count, total))

cogfile.close()

# make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])

pie(fracs, labels=labels, colors=('#CCFF00', '#CCFF33', '#333300', '#666600', '#999900', '#CCCC00', '#FFFF00', '#CC9933', '#CC6633', '#330000', '#660000', '#990000', '#CC0000', '#FF0000', '#FF3366', '#FF0033', '#99FF00', '#CCFF66', '#99CC33', '#666633', '#999933', '#CCCC33', '#FFFF33', '#996600', '#993300', '#663333', '#993333', '#CC3333', '#FF3333', '#CC3366', '#FF6699', '#FF0066'), autopct=None, shadow=True)
title('Cave biofilm COG categories', bbox={'facecolor':'0.8', 'pad':5})

show()
